int prime(int x)
{
    if (x < 2)
        return 0;
    for (int i = 2; i <= x / i; i++)
        if (x % i == 0)
            return 0;
    return 1;
}

int count(int x)
{
    int t = x;
    int p = 0;
    while (t > 0)
    {
        p++;
        t /= 10;
    }
    return p;
}

int mprime(int x)
{
    int mp = 0;
    int t = x;
    while (t > 9)
    {
        int p = count(t);
        while (p > 1)
        {
            int y = (int)pow(10, p--);
            int xx = t % y;
            if (prime(xx) && xx > 10 && xx > mp)
                mp = xx;
        }
        t /= 10;
    }
    return mp;
}